package com.example.goodsmanagementcabinet.hcamburntool;

public class hcamBurnOp {
    static {
        System.loadLibrary("SPHCamBurnOp");
    }

    /***
     *  A native method that is implemented by the 'native-lib' native library,
     *  which is packaged with this application
     */
    private native int sphCamOpenDevice(int jiDevFd, String jsDevPath);

    private native int sphCamPreBurn(int jsBinFileType, int[] jiResetFlag);

    private native int sphCamOpBurn(byte[] pbBinData, int jsDataSize, int[] jiResetFlag);

    private native void sphCamClose();

    private native int sphCamGetDeviceBCD();

    private native int sphcamGetDeviceSerial(byte[] pbSerial);
    //********************************************************************************

    private boolean m_bDeviceOpened;
    private boolean m_bDeviceResetFlag;
    private int m_sDeviceFD;        // Device file descriptor
    private String m_strDevicePath;    // Device path

    public void hcamBurnOpInit() {
        m_bDeviceOpened = false;
        m_bDeviceResetFlag = false;
        m_sDeviceFD = -1;
    }

    public int openDevice(int sDevFD, String strDevPath) {
        int tmp_bRet = 0;

        tmp_bRet = sphCamOpenDevice(sDevFD,
                strDevPath);

        if (1 == tmp_bRet) {
            m_bDeviceOpened = true;
            m_sDeviceFD = sDevFD;
            m_strDevicePath = strDevPath;
        }

        return tmp_bRet;
    }

    public void close() {
        if (m_bDeviceOpened) {
            sphCamClose();
            m_bDeviceOpened = false;
        }
    }

    public short getDeviceBCD() {
        short tmp_s16DeviceBCD = 0;

        tmp_s16DeviceBCD = (short) sphCamGetDeviceBCD();

        return tmp_s16DeviceBCD;
    }

    public byte[] getDeviceSerial() {
        int tmp_sRet = 0;
        byte[] tmp_bDeviceSerial = new byte[32];

        tmp_sRet = sphcamGetDeviceSerial(tmp_bDeviceSerial);
        if (1 == tmp_sRet) {
            return tmp_bDeviceSerial;
        } else {
            return null;
        }
    }

}
